package com.zyw.controller.production;


import com.zyw.entity.Order;
import com.zyw.entity.ProductionManagement;
import com.zyw.entity.RepertoryFinish;
import com.zyw.entity.RepertoryMaterial;
import com.zyw.from.ProductionFrom;
import com.zyw.from.repertoryFrom;
import com.zyw.service.order.OrderService;
import com.zyw.service.production.ProductionManagementService;
import com.zyw.util.GenerateOrdersIDUtil;
import com.zyw.util.ResultVOUtil;
import com.zyw.vo.LayUITableVO;
import com.zyw.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@Slf4j
@RequestMapping("/production/management")
public class ProductionManagementController {

    @Autowired
    public ProductionManagementService productionManagementService;
    @Autowired
    public OrderService orderService;


    //菜品类别展示
    @GetMapping("/index")
    public String index(Model model){


        return "production/management/index";

    }
    //获取菜品类别信息
    @GetMapping("/list")
    @ResponseBody
    public LayUITableVO<List<ProductionManagement>> list (@RequestParam(defaultValue = "1") Integer page,
                                                       @RequestParam(defaultValue = "10") Integer limit,
                                                          ProductionFrom from){

        Map<String ,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("limit",limit);
        map.put("from",from);
        LayUITableVO< List<ProductionManagement>> vo = productionManagementService.findPage(map);


        return vo;
    }





    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/add-ui")
    public String addUI(String orderId , Model model){

        model.addAttribute("orderId",orderId);

        Order order = orderService.selectById(orderId);
        String schedule = "0/"+order.getOrderNum();
        model.addAttribute("schedule",schedule);
        model.addAttribute("clothingId",order.getClothingId());
        return "production/management/add";

    }


    @PostMapping("/add")
    @ResponseBody
    public ResultVO add(ProductionManagement productionManagement){

        productionManagement.setId("PB"+GenerateOrdersIDUtil.generateOrdersID(9));
        productionManagement.setStatus(0);

        productionManagementService.save(productionManagement);



        return ResultVOUtil.ok();
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/edit-ui")
    public String editUI(String id , Model model){

       ProductionManagement productionManagement = productionManagementService.selectById(id);
        model.addAttribute("productionManagement",productionManagement);
        return "production/management/edit";

    }

    @PostMapping("/edit")
    @ResponseBody
    public ResultVO edit(ProductionManagement productionManagement){



        productionManagementService.updateSchedule(productionManagement);



        return ResultVOUtil.ok();
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/editStatus")
    public String editStatus(String id , Model model){

        ProductionManagement productionManagement = productionManagementService.selectById(id);
        model.addAttribute("productionManagement",productionManagement);
        return "production/management/editStatus";

    }

    @PostMapping("/addFinish")
    @ResponseBody
    public ResultVO addFinish(RepertoryFinish repertoryFinish){



        productionManagementService.updateStatus(repertoryFinish);



        return ResultVOUtil.ok();
    }

}
